import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace CmtContentArticleApi {
  export interface Article {
    id?: number;
    communityId?: number;
    merchantId?: number;
    categoryId?: number;
    title?: string;
    author?: string;
    authorUserId?: number;
    coverImage?: string;
    summary?: string;
    content?: string;
    contentType?: number;
    images?: string;
    videos?: string;
    attachments?: string;
    tags?: string;
    articleSource?: string;
    sourceUrl?: string;
    viewCount?: number;
    likeCount?: number;
    commentCount?: number;
    collectCount?: number;
    shareCount?: number;
    isTop?: number;
    isHot?: number;
    isRecommend?: number;
    allowComment?: number;
    publishStatus?: number;
    publishTime?: string;
    auditStatus?: number;
    auditUserId?: number;
    auditTime?: string;
    auditRemark?: string;
    sort?: number;
    createTime?: string;
  }

  export interface ArticlePageReqVO extends PageParam {
    title?: string;
    author?: string;
    categoryId?: number;
    publishStatus?: number;
    auditStatus?: number;
    isTop?: number;
    isHot?: number;
    isRecommend?: number;
    createTime?: string[];
  }
}

export function getArticlePage(params: CmtContentArticleApi.ArticlePageReqVO) {
  return requestClient.get<PageResult<CmtContentArticleApi.Article>>(
    '/cmt/content-article/page',
    { params },
  );
}

export function getArticle(id: number) {
  return requestClient.get<CmtContentArticleApi.Article>(
    `/cmt/content-article/get?id=${id}`,
  );
}

export function createArticle(data: CmtContentArticleApi.Article) {
  return requestClient.post('/cmt/content-article/create', data);
}

export function updateArticle(data: CmtContentArticleApi.Article) {
  return requestClient.put('/cmt/content-article/update', data);
}

export function deleteArticle(id: number) {
  return requestClient.delete(`/cmt/content-article/delete?id=${id}`);
}

export function deleteArticleList(ids: number[]) {
  return requestClient.delete(
    `/cmt/content-article/delete-list?ids=${ids.join(',')}`,
  );
}

export function exportArticle(params: CmtContentArticleApi.ArticlePageReqVO) {
  return requestClient.download('/cmt/content-article/export-excel', { params });
}
